package com.xbongbong.paas.config;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.service.init.InitMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 吴峰
 * @date 2021/05/21 14:38
 */
@Configuration
public class InitAppConfig  {

    @Autowired
    private ApplicationContext applicationContext;




    @Bean("initMenuMap")
    public Map<String, InitMenuService> initMenuServiceMap() {
        Map<String, InitMenuService> initMenuMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        Map<String, InitMenuService> initMenuServiceMap = applicationContext.getBeansOfType(InitMenuService.class);
        if (initMenuServiceMap.isEmpty()) {
            return initMenuMap;
        }
        initMenuServiceMap.forEach((key, item)->{
            item.alias().forEach(alias->{
                initMenuMap.put(alias, item);
            });
        });

        return initMenuMap;
    }

}
